package com.chenjun.core.dao.generator.mapper;

import com.chenjun.core.dao.generator.entity.SysResource;
import com.chenjun.core.dao.generator.entity.SysResourceExample;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.Update;

public interface SysResourceMapper {
    @Delete({
        "delete from sys_resource",
        "where id = #{id,jdbcType=VARCHAR}"
    })
    int deleteByPrimaryKey(String id);

    @Insert({
        "insert into sys_resource (id, name, ",
        "i18n_key, url, parent_id, ",
        "type, permissions, ",
        "sort_num, created_time, ",
        "icon)",
        "values (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, ",
        "#{i18nKey,jdbcType=VARCHAR}, #{url,jdbcType=VARCHAR}, #{parentId,jdbcType=VARCHAR}, ",
        "#{type,jdbcType=VARCHAR}, #{permissions,jdbcType=VARCHAR}, ",
        "#{sortNum,jdbcType=INTEGER}, #{createdTime,jdbcType=TIMESTAMP}, ",
        "#{icon,jdbcType=VARCHAR})"
    })
    @SelectKey(statement="SELECT replace(UUID(), '-', '')", keyProperty="id", before=true, resultType=String.class) 
    int insert(SysResource record);

    int insertSelective(SysResource record);

    List<SysResource> selectByExample(SysResourceExample example);

    @Select({
        "select",
        "id, name, i18n_key, url, parent_id, type, permissions, sort_num, created_time, ",
        "icon",
        "from sys_resource",
        "where id = #{id,jdbcType=VARCHAR}"
    })
    @ResultMap("BaseResultMap")
    SysResource selectByPrimaryKey(String id);

    int updateByPrimaryKeySelective(SysResource record);

    @Update({
        "update sys_resource",
        "set name = #{name,jdbcType=VARCHAR},",
          "i18n_key = #{i18nKey,jdbcType=VARCHAR},",
          "url = #{url,jdbcType=VARCHAR},",
          "parent_id = #{parentId,jdbcType=VARCHAR},",
          "type = #{type,jdbcType=VARCHAR},",
          "permissions = #{permissions,jdbcType=VARCHAR},",
          "sort_num = #{sortNum,jdbcType=INTEGER},",
          "created_time = #{createdTime,jdbcType=TIMESTAMP},",
          "icon = #{icon,jdbcType=VARCHAR}",
        "where id = #{id,jdbcType=VARCHAR}"
    })
    int updateByPrimaryKey(SysResource record);
}